/* GUI CONVERTED from rcrqmval.p (converter v1.75) Sun Jul 15 20:41:54 2001 */
/* rcrqmval.p - Release Management Customer Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.3.1.5 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96           BY: TSI *K005*    */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98          BY: *K1Q4* Alfred Tan    */
/* REVISION: 9.1    LAST MODIFIED: 02/21/00          BY: *N084* eww           */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00          BY: *N0KP* myb           */
/* $Revision: 1.3.1.5 $    BY: Rajiv Ramaiah    DATE: 07/12/01 ECO: *M1DX*       */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*AUTHORIZATION NUMBER VALIDATION*/

/*INPUT PARAMETERS*/
define input parameter address as character no-undo.
define input parameter start_date as date no-undo.
define input parameter authnbr as character no-undo.
define input parameter schedule_type as integer no-undo.

/*OUTPUT PARAMETERS*/
define output parameter rqmdet_recid as recid no-undo.

/*LOCAL VARIABLES*/
define variable shipto_id as character no-undo.
define variable cust_id as character no-undo.
define variable soshipto_id as character no-undo.
define variable socust_id as character no-undo.

for first ad_mstr
   fields (ad_addr ad_ref ad_type)
   where ad_addr = address
   no-lock:
end. /* FOR FIRST ad_mstr */

if available ad_mstr
then do:
   assign
      cust_id   = ad_addr
      shipto_id = ad_addr.

   if ad_type = "dock"
   then do:
      assign
         shipto_id = ad_ref
         cust_id   = ad_ref.

      for first ad_mstr
         fields (ad_addr ad_ref ad_type)
         where ad_addr = cust_id
         no-lock:
      end. /* FOR FIRST ad_mstr */
      cust_id = if  ad_type = "ship-to" and available ad_mstr
                then ad_ref else cust_id.
   end.
   else
      cust_id = if ad_type = "ship-to" then ad_ref else cust_id.
end. /*IF AVAILABLE ad_mstr*/

for each rqm_det
   fields (rqm_cat rqm_date rqm_line rqm_nbr rqm_type rqm_value)
   where rqm_type  > (if schedule_type = 3 then 2 else 0)
     and rqm_cat   = "AUTHNBR"
     and rqm_date  >= start_date
     and rqm_value = authnbr
     use-index rqm_value
   no-lock,
   sod_det
      fields (sod_line sod_nbr)
      where sod_nbr  = rqm_nbr
      and sod_line   = rqm_line
      no-lock
      by rqm_type descending:

   for first so_mstr
      fields (so_nbr so_ship)
      where so_nbr = sod_nbr
      no-lock:
   end. /* FOR FIRST so_mstr */
   if available so_mstr
   then

      for first ad_mstr
         fields (ad_addr ad_ref ad_type)
         where ad_addr = so_ship
         no-lock:
      end. /* FOR FIRST ad_mstr */
      if available ad_mstr
      then do:
         assign
         socust_id   = ad_addr
         soshipto_id = ad_addr.

         if ad_type = "dock"
         then do:
            assign
            soshipto_id = ad_ref
            socust_id   = ad_ref.

            for first ad_mstr
               fields (ad_addr ad_ref ad_type)
               where ad_addr = socust_id
               no-lock:
            end. /* FOR FIRST ad_mstr */
            socust_id = if ad_type = "ship-to" and available ad_mstr
                        then ad_ref else socust_id.
         end.
         else
            socust_id = if ad_type = "ship-to" then ad_ref else socust_id.
   end. /*IF AVAILABLE ad_mstr*/

   if soshipto_id = shipto_id
   or socust_id   = cust_id
   then do:
      rqmdet_recid = recid(rqm_det).
      leave.
   end.
end. /* FOR EACH rqm_det */
